<template>
  <div v-if="groupIndexItem" class="butt-list-stys2">
    <div
      v-for="(item, index) in topitemSelectList"
      :key="item.equipmentTypeId"
      :class="index === itemtypeactive ? 'basebut1' : 'basebut2'"
      @click="itemtypeactive = index"
    >
      <!-- {{ index }} -->
      {{ item.equipmentTypeName }}
    </div>
  </div>
</template>

<script>
import equipmentTypeManage from "@/api/digital-operation/equip-fac-manage/equip-type-manage";
export default {
  props: {
    groupid: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      itemtypeactive: 0,
      topitemSelectList: [],
      // groupIndex: 0,
      groupIndexItem: true
    };
  },
  watch: {
    itemtypeactive(newvalue) {
      this.selbut(newvalue);
    },
    groupid(e) {
      if (e) {
        this.itemtypeactive = 0
        this.topitemSelectList = []
        this.groupIndexItem = true
        this.queryEquipmentTypeList(e)
        this.selbut(0);
      }
    }
  },
  created() {
    setTimeout(() => {
      this.queryEquipmentTypeList(this.groupid);
    }, 300)
  },
  mounted() {
    setTimeout(() => {
      this.selbut(0);
    }, 300)
  },
  methods: {
    selbut(i) {
      // console.log(i)
      setTimeout(() => {
        if (this.topitemSelectList[i]) {
          this.$emit("topitemtypes", this.topitemSelectList[i]["equipmentTypeId"]);
          this.$emit("topitemName", this.topitemSelectList[i]["equipmentTypeName"]);
        }
      }, 300)
    },
    async queryEquipmentTypeList(e) {
      let params = {
        organizationNo: sessionStorage.organizationNo,
        groupId: e
      }
      const { data: res } = await equipmentTypeManage.queryEquipmentTypeList(params);
      this.topitemSelectList = res;
    }
  }
};
</script>
<style lang="scss" scoped>
.butt-list-stys2 {
  width: 99%;
  // height: 60px;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  // margin: 10px 0;
  overflow-x: auto;
}
.basebut1 {
    min-width: 100px;
    height: 24px;
    line-height: 22px;
    text-align: center;
    // background-color: transparent;
    background-image: linear-gradient(#0fa1d2,#1087af,#106f8f);
    border: #f6f9f9 1px solid;
    // box-sizing: border-box;
    border-radius: 15px;
    color: #ffffff;
    cursor: pointer;
    margin: 3px 5px;
    padding-left: 10px;
    padding-right: 10px;
    // transform: translateY(50%);
}
.basebut2 {
    min-width: 100px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    background-color: #106986;
    border-radius: 15px;
    color: #ffffff;
    cursor: pointer;
    margin: 3px 5px;
    padding-left: 10px;
    padding-right: 10px;
    // transform: translateY(50%);
}
</style>
